package com.tailyou.hms.firstapp.act;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tailyou.hms.firstapp.R;

public class TxtWdgActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_txt_wdg);
        TextView tvMarquee = findViewById(R.id.textView7);
        tvMarquee.setSelected(true);
        EditText edt1 = findViewById(R.id.edt1);
        edt1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                Toast.makeText(TxtWdgActivity.this, s.toString(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Toast.makeText(TxtWdgActivity.this, s.toString(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void afterTextChanged(Editable s) {
                //Toast.makeText(WidgetActivity.this, s.toString(), Toast.LENGTH_SHORT).show();
            }
        });

        edt1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    Toast.makeText(TxtWdgActivity.this, "搜索", Toast.LENGTH_SHORT).show();
                    return true;
                } else if (actionId == EditorInfo.IME_ACTION_DONE) {
                    Toast.makeText(TxtWdgActivity.this, "完成", Toast.LENGTH_SHORT).show();
                    return true;
                }
                return false;
            }
        });

        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TxtWdgActivity.this, "点击了按钮", Toast.LENGTH_SHORT).show();
            }
        });

    }
}